home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
basic
/
hugearr.zip
/
HUGESAVE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-04-02
|
2KB
|
60 lines
#define NOCOMM
#include <windows.h>
#include "hugearr.h"
/* Store the contents of a huge array in an operating system file. */
/* VBM: Declare Function VBHugeSave& Lib "hugearr.dll" Alias "VBHugeSave" (ByVal hArray%, ByVal NEl&, ByVal RecLen%, ByVal Fn$) */
long FAR PASCAL
VBHugeSave(int hArray, long nelements, int OutLen, LPSTR FileSpec)
{
int hSaveFile; /* handle to the save file */
HPBYTE FmBegin; /* pointer for first element */
HPBYTE FmElem; /* pointer to array element */
long element; /* element in the huge array */
PHUGEDESC pArray; /* pointer to array descriptor */
DecCheckHandle(hArray);
pArray = (PHUGEDESC) LocalLock(hLocalMem) + hArray;
CheckNotAllocYet(pArray);
if (pArray -> ubound + 1 < nelements || nelements < 0)
{
/* subscript out of range */
LocalUnlock(hLocalMem);
return HA_SUBSCRIPT;
}
/* Open the file */
hSaveFile = _lopen(FileSpec, OF_WRITE);
if (hSaveFile < 0)
{
LocalUnlock(hLocalMem);
return HA_FILEOPENERROR;
}
/* calculate pointer to element */
FmBegin = (HPBYTE) GlobalLock(pArray -> handle);
for(element = 0L; element < nelements; element++)
{
FmElem = FmBegin + HugeElementOffset(element, pArray->perseg, pArray->recsize);
/* Write out the record */
if(_lwrite(hSaveFile, FmElem, OutLen) < 0)
{
element = HA_FILEWRITEERROR;
break;
}
}
/* Wrap up and return */
GlobalUnlock(pArray -> handle);
LocalUnlock(hLocalMem);
_lclose(hSaveFile);
return element;
}